/* 636. 函数的独占时间 */
/**
 * @param {number} n
 * @param {string[]} logs
 * @return {number[]}
 */
var exclusiveTime = function (n, logs) {
	const stack = [] //{idx,开始运行的时间}
	const res = new Array(n).fill(0)
	for (const log of logs) {
		const [idx, type, timestamp] = log.split(':')
		if (type === 'start') {
			if (stack.length) {
				res[stack[stack.length - 1][0]] +=
					timestamp - stack[stack.length - 1][1]
				stack[stack.length - 1][1] = parseInt(timestamp)
			}
			stack.push([idx, timestamp])
		} else {
			const t = stack.pop()
			res[t[0]] += timestamp - t[1] + 1
			if (stack.length) {
				stack[stack.length - 1][1] = parseInt(timestamp) + 1
			}
		}
	}
	return res
}
exclusiveTime(2, [
	'0:start:0',
	'0:start:2',
	'0:end:5',
	'1:start:6',
	'1:end:6',
	'0:end:7',
])
